import { getToken } from '@/utils/CookieUtils'

const state = {
  token: getToken(),
  username: '',
  avatar: '',
  menus: ''
}

const mutations = {
  setUsername: (state, username) => {
    state.username = username
  },
  setAvatar: (state, avatar) => {
    state.avatar = avatar
  },
  setMenus: (state, menus) => {
    state.menus = menus
  }
}

const actions = {
  currentUserInfo({ commit }, data) {
    commit('setUsername', data.username)
    commit('setAvatar', data.avatar)
    commit('setMenus', data.menus)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

